// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Author: wsfuyibing <682805@qq.com>
// Date: 2024-12-05

package filter

import "strings"

// Format is a type name used to define the format of input message body or
// dispatched response body.
type Format string

const (
	FormatJson  Format = "JSON"
	FormatPlain Format = "PLAIN"
	FormatXml   Format = "XML"

	undefinedFormat            Format = ""
	undefinedFormatContentType        = ""
)

var formatContentType = map[Format]string{
	FormatJson:  "application/json",
	FormatPlain: "text/plain",
	FormatXml:   "application/xml",
}

// ContentType returns content type of format for http request.
func (o Format) ContentType() string {
	if s, ok := formatContentType[o]; ok {
		return s
	}
	return undefinedFormatContentType
}

func (o Format) IsJson() bool  { return o == FormatJson }
func (o Format) IsPlain() bool { return o == FormatPlain }
func (o Format) IsXml() bool   { return o == FormatXml }

func (o Format) Lower() Format   { return Format(strings.ToLower(o.String())) }
func (o Format) String() string  { return string(o) }
func (o Format) Undefined() bool { return o == undefinedFormat }
func (o Format) Upper() Format   { return Format(strings.ToUpper(o.String())) }
